package cn.xzqwjw.taskmanager.common.validator;

import cn.hutool.core.util.IdcardUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Objects;

/**
 * @author rush
 */
public class IdCardValidatorClass implements ConstraintValidator<IdCardValidator, Object> {

  @Override
  public void initialize(IdCardValidator validator) {
  }

  /**
   * 用户输入的身份证号码
   *
   * @param value 用户输入的值，如从前端传入的某个值
   */
  @Override
  public boolean isValid(Object value, ConstraintValidatorContext cvContext) {
    if (Objects.isNull(value)) {
      return true;
    }
    return IdcardUtil.isValidCard(value.toString());
  }

}